package com.fr.report.script.function;

import com.fr.report.script.Function;
import com.fr.report.script.Function.Type;
import com.fr.report.script.NormalFunction;
import com.fr.report.script.Primitive;

public class FACT extends NormalFunction
{
  public Object run(Object[] paramArrayOfObject)
  {
    if (paramArrayOfObject.length < 1)
      return Primitive.ERROR_NAME;
    Object localObject = null;
    for (int i = 0; i < paramArrayOfObject.length; ++i)
    {
      localObject = paramArrayOfObject[i];
      if (localObject instanceof Number)
      {
        double d = ((Number)localObject).doubleValue();
        if (d == 0.0D)
          return new Integer(1);
        long l = 1L;
        for (int j = 1; j <= (int)d; ++j)
          l *= j;
        return new Long(l);
      }
    }
    return new Integer(0);
  }

  public Function.Type getType()
  {
    return Function.MATH;
  }

  public String getCN()
  {
    return "FACT(number):返回数的阶乘，一个数的阶乘等于 1*2*3*...*该数。\nnumber:要计算其阶乘的非负数。如果输入的 number 不是整数，则截尾取整。\n示例:\nFACT(1) 等于 1\nFACT(1.9) 等于 FACT(1) 等于 1\nFACT(0) 等于 1\nFACT(5) 等于 1*2*3*4*5 等于 120\n";
  }

  public String getEN()
  {
    return "FACT(number): Returns the factorial of a number. The factorial of a number is equal to 1*2*3*...* number.\nNumber is the nonnegative number you want the factorial of. If number is not an integer, it is truncated.\n\nExample:\n   FACT(1) = 1\n   FACT(1.9) = FACT(1) = 1\n   FACT(0) = 1\n   FACT(5) = 1*2*3*4*5 = 120\n";
  }
}